## Compiler and linker settings
HOME = /etc
PRJ_HOME = $(HOME)/dev/animation
CXX = g++
CXXFLAGS = -g -D _DEBUG
LIBS = OGRE OIS
LIBOPTS = -L$(HOME)/dev/gamut/lib -L$(HOME)/dev/local/tinyxml -lGamut -ltinyxml $(shell pkg-config --libs $(LIBS))
INCLUDEOPTS = -I$(HOME)/dev/gamut/include $(shell pkg-config --cflags $(LIBS))
SRC = $(wildcard *.cpp)
OBJ = $(patsubst %.cpp,obj/%.o,$(SRC))
DEP = $(patsubst obj/%.o,obj/%.d,$(OBJ))
TARGET = $(PRJ_HOME)/animation

all: $(TARGET)

# build source files
obj/%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< $(INCLUDEOPTS) -o $@

# auto-build dependencies (make will update src on header file change)
obj/%.d: %.cpp
	$(CXX) -MM $(CXXFLAGS) -c $< $(INCLUDEOPTS) > $@
	@mv -f $@ $@.tmp
	@sed -e 's|.*:|$(@:.d=.o):|' < $@.tmp > $@
	@sed -e 's/.*://' -e 's/\\$$//' < $@.tmp | fmt -1 | \
		sed -e 's/^ *//' -e 's/$$/:/' >> $@
	@rm -f $@.tmp

-include $(DEP)

# copy all static libs to the obj directory to include in the final library
$(TARGET): $(OBJ)
	$(CXX) $(CXXFLAGS) -o $@ $(OBJ) $(LIBOPTS)

clean:
	rm -f obj/*.o $(DEP) $(TARGET)

depend:
	@echo invalid, dependencies auto-created
